package com.zprmb.udzt.activity;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.ExpandableBean;
import com.zprmb.udzt.util.ExplosionField;

import java.text.DecimalFormat;
import java.util.List;

import static com.zprmb.udzt.R.id.text_zhekou;

public class ExpandableBaseAdapter_NewBeiFen extends BaseAdapter {
    private Context context;
    private List<ExpandableBean> list;
    DecimalFormat df = new DecimalFormat("###0.00");
    DecimalFormat df2 = new DecimalFormat("###0.0");
    private ExplosionField mExplosionField;//粉碎动画执行方法类

    public ExpandableBaseAdapter_NewBeiFen(Context context, List<ExpandableBean> list) {
        super();
        mExplosionField = ExplosionField.attach2Window((Activity) context);
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean hasStableIds() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHelp h = null;
        if (convertView == null) {
            h = new ViewHelp();
            convertView = LayoutInflater.from(context).inflate(R.layout.group_demo, null);
            h.li_newuser = (LinearLayout) convertView.findViewById(R.id.li_newuser);
            h.tv_title = (TextView) convertView.findViewById(R.id.tv_product_name);
            h.tv_red = (TextView) convertView.findViewById(R.id.tv_new_user);
            h.tv_fresh = (TextView) convertView.findViewById(R.id.tv_fresh);
            h.tv_coupon = (TextView) convertView.findViewById(R.id.conduct_addrate);
            h.tv_minamount = (TextView) convertView.findViewById(R.id.tv_minamount);
            h.text_zhekou = (TextView) convertView.findViewById(text_zhekou);
            h.v6_ud_invest_increaseNum = (TextView) convertView.findViewById(R.id.v6_ud_invest_increaseNum);
            h.tv_name = (TextView) convertView.findViewById(R.id.conduct_name);
            h.tv_time = (TextView) convertView.findViewById(R.id.conduct_time);
            h.tv_rate = (TextView) convertView.findViewById(R.id.conduct_rate);
            h.tv_rateadd = (TextView) convertView.findViewById(R.id.home_rateadd);
            h.tv_investAmount = (TextView) convertView.findViewById(R.id.conduct_investAmount);
            h.li_jiaxi = (LinearLayout) convertView.findViewById(R.id.li_jiaxi);
            h.img_list_status = (ImageView) convertView.findViewById(R.id.img_list_status);
            h.img_pl_reward = (ImageView) convertView.findViewById(R.id.img_pl_reward);
            h.tv_pl_reward = (TextView) convertView.findViewById(R.id.tv_pl_reward);
            h.sk_progresss = (ProgressBar) convertView.findViewById(R.id.sk_progresss);

            convertView.setTag(h);
            convertView.setTag(h);
        } else {
            h = (ViewHelp) convertView.getTag();
        }
        if (list.get(position).isFlagRebate() == true) {
            h.text_zhekou.setVisibility(View.VISIBLE);
        } else {
            h.text_zhekou.setVisibility(View.VISIBLE);
        }


        if ("FIRST_INVEST".equals(list.get(position).getProduct())) {

            h.li_newuser.setVisibility(View.GONE);
            h.tv_fresh.setVisibility(View.VISIBLE);
        } else {

            h.tv_fresh.setVisibility(View.GONE);
            h.li_newuser.setVisibility(View.VISIBLE);
        }
        h.tv_title.setText(list.get(position).getProductName());
        if (list.get(position).isFlagRaiseInterest()) {
            h.tv_coupon.setVisibility(View.VISIBLE);
//            h.text_zhekou.setVisibility(View.VISIBLE);
        } else {
            h.tv_coupon.setVisibility(View.VISIBLE);
            h.tv_coupon.setVisibility(View.VISIBLE);
        }
        if (list.get(position).isFlagRedpack()) {
            h.tv_red.setVisibility(View.VISIBLE);
        } else {
            h.tv_red.setVisibility(View.VISIBLE);
        }
        if (list.get(position).getMinAmount() != null) {

            h.tv_minamount.setText(list.get(position).getPrompt());
        }
        // TODO Auto-generated method stub



    /*    Product_Uplan uplan = list.get(position).getList().get(position);
        if (uplan.getStatus().equals("COLLECTING")) {
            h.img_list_status.setVisibility(View.GONE);
        } else if (uplan.getStatus().equals("SETTLEMENTED")) {
            h.img_list_status.setVisibility(View.VISIBLE);
            h.img_list_status.setImageBitmap(BitmapUtils.readBitMap(context, R.drawable.img_list_shouyiz));
        } else if (uplan.getStatus().equals("REPAYED")) {
            h.img_list_status.setVisibility(View.VISIBLE);
            h.img_list_status.setImageBitmap(BitmapUtils.readBitMap(context, R.drawable.img_list_back_money));
        } else {
            h.img_list_status.setVisibility(View.VISIBLE);
            h.img_list_status.setImageBitmap(BitmapUtils.readBitMap(context, R.drawable.img_list_finsh));
        }
        h.v6_ud_invest_increaseNum.setText(list.get(position).getList().get(position).getMinAmount() + "元起投");
        h.tv_name.setText(list.get(position).getList().get(position).getProductName());
//		}
        h.sk_progresss.setProgress((int) (uplan.getDegree() * 10));
        h.tv_rate.setText(df.format(Double.parseDouble(list.get(position).getList().get(position).getFixedRate())));
        if (!uplan.getFlagNowEffective()) {
            h.tv_pl_reward.setVisibility(View.GONE);
            if ("nonArrivalOpenTime".equals(uplan.getNonArrivalOpenTimeStatus())) {
                h.tv_pl_reward.setVisibility(View.VISIBLE);
                h.tv_pl_reward.setText(Regular.getMilliToHour_Min(uplan.getOpenTime()) + "开放");
                h.img_pl_reward.setVisibility(View.GONE);
            } else {
                if ("true".equals(uplan.getFlagFresh())) {
                    BbtApplication.getInstance().display(uplan.getFreshPictureAddress(), h.img_pl_reward);
                    h.img_pl_reward.setVisibility(View.VISIBLE);
                } else {
                    h.img_pl_reward.setVisibility(View.GONE);
                }
            }
        } else {
            if ("nonArrivalOpenTime".equals(uplan.getNonArrivalOpenTimeStatus())) {
                h.tv_pl_reward.setVisibility(View.VISIBLE);
                h.tv_pl_reward.setText(Regular.getMilliToHour_Min(uplan.getOpenTime()) + "开放");
                h.img_pl_reward.setVisibility(View.GONE);
            } else {
                if ("true".equals(uplan.getFlagFresh())) {
                    h.tv_pl_reward.setVisibility(View.GONE);
                    h.img_pl_reward.setVisibility(View.VISIBLE);
                    BbtApplication.getInstance().display(uplan.getFreshPictureAddress(), h.img_pl_reward);
                } else {
                    h.tv_pl_reward.setVisibility(View.VISIBLE);
                    h.tv_pl_reward.setText("平台奖励");
                    h.img_pl_reward.setVisibility(View.GONE);
                }

            }

        }*/
 /*
        if (list.get(position).getList().get(position).getFixedRateAdd().equals("0")) {
            h.li_jiaxi.setVisibility(View.GONE);

            h.tv_rate.setText(df.format(Double.parseDouble(list.get(position).getList().get(position).getFixedRate())));
        } else {
            h.li_jiaxi.setVisibility(View.VISIBLE);
//				h.li_jiaxi.setBackgroundResource(R.drawable.jiaxi);
            h.tv_rate.setText(df.format(Double.parseDouble(list.get(position).getList().get(position).getFixedRate()) - Double.parseDouble(list.get(position).getList().get(position).getFixedRateAdd())));
            h.tv_rateadd.setText(df.format(Double.parseDouble(list.get(position).getList().get(position).getFixedRateAdd())) + "%");
        }
*/

/*        h.tv_time.setText(list.get(position).getList().get(position).getDays());
        h.tv_investAmount.setText(Regular.getDecimalFormatTwo(Double.parseDouble(list.get(position).getList().get(position).getRemainAmount()) / 10000));*/


        return convertView;

    }




    class ViewHelp {
        private TextView tv_title, tv_red;
        private TextView tv_minamount, tv_fresh;
        private LinearLayout li_newuser;

        private TextView v6_ud_invest_increaseNum, tv_pl_reward;
        private TextView tv_name, tv_coupon, tv_rate, tv_rateadd, tv_time, tv_investAmount, tv_newuser, tv_coupon_type, newuser;
        private LinearLayout li_jiaxi, li_redjiaxi, li_intent;
        private Button btn_invest;
        private ProgressBar sk_progresss;
        private ImageView img_list_status;
        private ImageView img_pl_reward;
        private ImageView img_group;
        private TextView text_zhekou;
    }
}

